<template>
  <div class="container">
    <el-dialog title="题目审核" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item>
          <el-radio v-model="form.chkState" :label="1">通过</el-radio>
          <el-radio v-model="form.chkState" :label="2">拒绝</el-radio>
        </el-form-item>
        <el-form-item>
          <el-input type="textarea" v-model="form.chkRemarks"  placeholder="请输入审核意见"/>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="close">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number
    }
  },
  data () {
    return {
      form: {
        chkState: 1,
        chkRemarks: ''
      },
      rules: {
        chkState: [
          { required: true, message: '请选择审核结果', trigger: 'change' }
        ],
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' }
        ]
      }

    }
  },
  methods: {
    async close () {
      if (this.form.chkRemarks === '') {
        this.$message.error('请填写审核意见')
      } else {
        const form = {
          id: this.id,
          ...this.form
        }
        const { data } = await choiceCheck(form)
        if (data.success) {
          this.$message({
            message: '审核成功',
            type: 'success'
          })
          this.$emit('close', !this.dialogVisible)
        }
      }
    },
    handleClose (done) {
      this.$emit('close', !this.dialogVisible)
      if (this.dialogVisible === false) {
        done()
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
